﻿using MediatR;
using PublicClass;
using S.RBAC.Infrastructure.Interface;
using S.RBAC.Read.Api.Application.Command.DepartmentCommand;

namespace S.RBAC.Read.Api.Application.CommandHandlers.DepartmentHandler
{
    public class DepartmentGetInfoCommandHandler : IRequestHandler<DepartmentGetInfoCommand, List<SelectList>>
    {
        protected readonly IDepartmentRepository _department;

        public DepartmentGetInfoCommandHandler(IDepartmentRepository department)
        {
            _department = department;
        }

        public async Task<List<SelectList>> Handle(DepartmentGetInfoCommand request, CancellationToken cancellationToken)
        {
            var list = await _department.GetAllDepartment();

            List<SelectList> selectLists = new List<SelectList>();

            foreach (var department in list)
            {
                selectLists.Add(new SelectList
                {
                    Id = department.DepartId,
                    Name = department.DepartName
                });
            }

            return selectLists;
        }
    }
}
